<?php echo $this->render('./includes/header.phtml');?>
<?php echo $this->render('./includes/fix_top_menu.phtml');?>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
	<div id="container" class="row-fluid">
		<?php echo $this->render('./includes/menu.phtml');?>
		<div id="main-content">
			<div class="container-fluid">
				<div class="row-fluid">
					<div class="span12">
						<h3 class="page-title">
							Quản lí địa điểm  <small></small>
						</h3>
					</div>
				</div>
							<div class="row-fluid">
					<div class="span12">
						<div class="widget">
							<div class="widget-title">
							
								<h4>
									<i class="icon-reorder"></i>Tổng số địa điểm : <?php echo $this->total_location;?>
								</h4>
								<div class="pull-right span3">
								<a href="<?php echo $this->baseUrl('/location/add/')?>" class="btn btn-success span12 pull-right" style="margin-top: 3px; margin-right: 3px;"> <i class="icon-plus icon-white"></i>  Thêm mới địa điểm </a>
								</div>
								<?php 
								if(count($this->arrListCity) != 0) {
								?>
								<div class="pull-right span4">
									<select data-placeholder="Chọn 1 tỉnh/thành phố để lọc kết quả hiển thị "
											class="chosen-with-diselect span12" tabindex="-1" id="selCSI"
											onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
											<option value="" />
											<option value="<?php echo $this->baseUrl('/location/');?>"> -- Tất cả -- </option>
											<?php foreach ($this->arrListCity as $city) {?>
											<option value="<?php echo $this->baseUrl('/location/'.'?city_id='.$city['city_id']);?>" <?php echo isset($this->arrParam['city_id']) && ($this->arrParam['city_id'] == $city['city_id']) ? 'selected="selected"' : ''; ?>><?php echo $city['name'];?></option>
											<?php }?>
										</select>
								</div>
								<?php 
								}
								?>
								
							</div>
							
							<div class="widget-body">
								<?php echo $this->render('./includes/display_alert_message.phtml');?>
								 
								 <?php if(count($this->arrMapLocLat) != 0) {?>
								 <div class="row-fluid" style="margin-bottom: 30px;">
					<div class="span12">
								 <div id="map" style="height: 250px; width: 100%;">
</div>
<script type="text/javascript">
    var locations = [
      <?php 
      $lFirstLat = 0;
      $lFirstLon = 0;
      $iTotalMap = count($this->arrMapLocLat);
      
      for($i = 0; $i < $iTotalMap; $i++) {
		if($i == 0) {
			$lFirstLat = $this->arrMapLocLat[$i];
			$lFirstLon = $this->arrMapLocLon[$i];
		}
	 ?>
      ['<?php echo $this->arrMapLocName[$i];?>', <?php echo $this->arrMapLocLat[$i];?>, <?php echo $this->arrMapLocLon[$i];?>, <?php echo $i;?>]
      <?php echo $i == $iTotalMap ? "" : ","?>
	  <?php
	  }?>
    ];
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: new google.maps.LatLng(<?php echo $lFirstLat;?>, <?php echo $lFirstLon;?>),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
 
    var infowindow = new google.maps.InfoWindow();
 
    var marker, i;
 
    for (i = 0; i < locations.length; i++) { 
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
 
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  </script>
				</div>
				</div>
				<?php }?>
								<table class="table table-striped table-bordered" id="sample_1">
									<thead>
										<tr>
											<th>Tên </th>
											<th class="hidden-phone">Tỉnh/Thành phố </th>
											<th class="hidden-phone">Người tạo </th>
											<th class="hidden-phone">Ảnh </th>
											<th class="hidden-phone">Ngày tạo </th>
											<th class="hidden-phone span4 "></th>
										</tr>
									</thead>
									<tbody>
									<?php 
									if(count($this->arrLoc) != 0) {
									$iCountLoc = 0;
									foreach ($this->arrLoc as $loc) {?>
										<tr class="odd gradeX">
											<td><?php echo  $loc['name']; ?></td>
											<td class="hidden-phone">
											<?php if(isset($this->arrCity[$iCountLoc][0]['name'])) {?>
											<?php echo $this->arrCity[$iCountLoc][0]['name'];?>
											<?php }?>
											</td>
											<td class="hidden-phone">
												<?php if(isset($this->arrUser[$iCountLoc][0]['username'])) {?>
												<?php echo $this->arrUser[$iCountLoc][0]['username'];?>
												<?php }?>
											</td>
											<td class="hidden-phone">
												<?php if(isset($this->arrPhoto[$iCountLoc][0]['photo_link'])) {?>
												<div class="thumbnail" style="height: 50px; width: 50px;">
												<div class="item" style="height: 50px; width: 50px;">
													<a class="fancybox-button" data-rel="fancybox-button"
														title="" href="<?php echo  $this->baseUrl(UPLOAD_PHOTO_DIRECTORY.$this->arrPhoto[$iCountLoc][0]['photo_link']); ?>"><div
															class="zoom">
															<img src="<?php echo  $this->baseUrl(UPLOAD_PHOTO_DIRECTORY.$this->arrPhoto[$iCountLoc][0]['photo_link']); ?>" alt="" style="height: 50px; width: 50px;" />
															<div class="zoom-icon" style="height: 50px; width: 50px;"></div>
														</div></a>
													</div>
												</div>
												<?php }?>
											</td>
											<td class="center hidden-phone"><?php echo  $loc['created_time']; ?></td>
											<td class="hidden-phone">
											
												<a href="#myModal<?php echo  $loc['location_id']; ?>"
										role="button" class="btn" data-toggle="modal">Chi tiết </a>
										<a href="<?php echo $this->baseUrl('/location/edit/?location_id='.$loc['location_id']); ?>"
										class="btn btn-primary"> <i class="icon-pencil"></i> Sửa </a>
										<div id="myModal<?php echo  $loc['location_id']; ?>" class="modal hide fade" tabindex="-1"
										role="dialog" aria-labelledby="myModalLabel<?php echo  $loc['location_id']; ?>"
										aria-hidden="true">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal"
												aria-hidden="true">×</button>
											<h3 id="myModalLabel2"><?php echo  ($loc['name']); ?></h3>
										</div>
										<div class="modal-body">
											<p><span class="span3">Tỉnh/Thành phố : </span><span class="span9">
											<?php if(isset($this->arrCity[$iCountLoc][0]['name'])) {?>
											<?php echo ($this->arrCity[$iCountLoc][0]['name']);?>
											<?php }?>
											</span></p>
											<p><span class="span3">Tạo bởi  : </span><span class="span9"><?php echo ($this->arrUser[$iCountLoc][0]['username']);?></span></p>
											<?php if(count($this->arrPhoto[$iCountLoc])) {?>
											<p><span class="span3">Ảnh  : </span><span class="span9">
												<?php foreach ($this->arrPhoto[$iCountLoc] as $photo) {?>
												<img alt="" src="<?php echo $this->baseUrl(UPLOAD_PHOTO_DIRECTORY.$photo['photo_link']);?>" style='width: 80px; height: 90px; margin-left: 10px; margin-top: 10px;'>
												<?php }?>
												</span></p>
											<?php }?>
											<p><span class="span3">Mô tả  : </span><span class="span9"><?php echo  ($loc['description']); ?></span></p>
											<p><span class="span3">Latitude - Longitude : </span><span class="span9"><?php echo  $loc['latitude']; ?> - <?php echo  $loc['longitude']; ?>
											<a href="<?php echo $this->baseUrl('/location/edit/?location_id='.$loc['location_id']); ?>"
												class="btn btn-info"> <i class="icon-map-marker"></i> Map</a>
											</span></p>
											<p><span class="span3">Like : </span><span class="span9"><?php echo  count($this->arrLike[$iCountLoc]); ?></span></p>
											<p><span class="span3">Ngày tạo/Ngày sửa : </span><span class="span9"><?php echo  $loc['created_time']; ?> / <?php echo  $loc['updated_time']; ?></span></p>
										</div>
										<div class="modal-footer">
											<button data-dismiss="modal" class="btn btn-primary">OK</button>
										</div>
									</div>
									<a href="<?php echo $this->baseUrl('/location/?delete=1&loc_id='.$loc['location_id']); echo isset($this->arrParam['city_id']) ? "&city_id=".$this->arrParam['city_id'] : "";?>" class="btn btn-danger" title="Xoá " onclick="return confirm('Xoá địa điểm?');"> <i class="icon-trash"></i> Xoá </a>
								
												</td>
										</tr>
										<?php 
										$iCountLoc++;
										}
										}?>
									</tbody>
								</table>
								<?php if(count($this->arrLoc) != 0) {?>
 								<?php echo $this->paginationControl($this->arrLoc, 'Sliding' , './includes/pagination.phtml'); ?>
 								<?php }?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<?php echo $this->render('./includes/footer.phtml');?>